<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title></title>
		<!--标准mui.css-->
		<link rel="stylesheet" href="../css/mui.min.css">
		<!--App自定义的css-->
		<link rel="stylesheet" type="text/css" href="../css/app.css" />
		<link href="../css/mui.picker.css" rel="stylesheet" />
		<link href="../css/mui.poppicker.css" rel="stylesheet" />
		<link rel="stylesheet" href="../css/mui.min.css">
		<link rel="stylesheet" type="text/css" href="../css/mui.picker.min.css" />
		<script src="../js/jquery-1.6.2.min.js"></script>
		<style>
			.mui-btn {
				font-size: 16px;
				padding: 8px;
				margin: 3px;
			}
			
			span.mui-content-padded {
				margin-left: 3px;
				margin-top: 20px !important;
			}
			
			span.mui-content-padded:first-child {
				margin-top: 12px !important;
			}
			
			.ui-alert {
				text-align: center;
				padding: 20px 10px;
				font-size: 16px;
			}
			
			.worktype {
				width: 50%;
				float: left;
			}
			
			.bkys {
				border-style: ridge;
			}
			
			span {
				margin-top: 10px;
			}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav" style="height: 55px;">
			<div style="margin-top: 15px;"></div>
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">紧急发布</h1>
		</header>
		<div id="" style="margin-top: 60px;">

		</div>
		<span class="mui-content-padded" style="margin-left: 20px;">选择加急金额</span>
		<div id="" style="margin-left: 10%;margin-top: 20px;">
			<div id="">
				<button type="button" class="mui-btn mui-btn-primary mui-btn-outlined" style="width: 40%;height: 50px;" onclick="topublish(this,1)">
					20元
				</button>
				<button type="button" class="mui-btn mui-btn-primary mui-btn-outlined" style="width: 40%;height: 50px;" onclick="topublish(this,'1')">
					30元
				</button>
			</div>
			<div id="" style="margin-top: 15px;">
				<button type="button" class="mui-btn mui-btn-primary mui-btn-outlined" style="width: 40%;height: 50px;" onclick="topublish(this,1)">
					50元
				</button>
				<button type="button" class="mui-btn mui-btn-primary mui-btn-outlined" style="width: 40%;height: 50px;" onclick="topublish(this,1)">
					100元
				</button>
			</div>

		</div>
		<div id="" style="height: 30px;">

		</div>
		<span class="" style="margin-left:5% ">自定义加急金额</span>
		<div id="" class="mui-input-row" style="margin-top: 20px;margin-left: 10%;margin-right: 10%;">

			<input id="UrgentSalary" style="text-align: center;background: #FFFFFF;border:2px solid gainsboro;width: 40%;float: left;" id="onemoney" type="number" onfocus="updatetitle(this)">
			<span style="margin-left:10px ;float: left;">元</span>
			<button id="pubbt" type="button" class="mui-btn mui-btn-primary mui-btn-outlined" style="width: 40%;float: left;margin-left: 20px;" onclick="topublish(this,2)">发布</button>
		</div>

		<div id="">

		</div>
		<div id="" style="margin-left: 10%;margin-right: 10%;margin-top: 20px;">
			<p>提示：</p>
			<p style="text-indent: 2em;line-height: 3em;">加急发布将需要你提前支付金额，由平台进行保管。当有用户接单并开始工作时，我们将把加急金额直接转入接单人的账户。若无人接单或者发布失败，您可以在我的账户页面进行提现。</p>
		</div>
		<script src="../js/urlconfiguration.js"></script>
		<script src="../js/mui.min.js"></script>
		<script src="../js/mui.picker.min.js"></script>
		<script src="../js/mui.picker.js"></script>
		<script src="../js/mui.poppicker.js"></script>
		<script src="../js/city.data.js" type="text/javascript" charset="utf-8"></script>
		<script src="../js/city.data-3.js" type="text/javascript" charset="utf-8"></script>
		<!--<script src="../js/myadd.js"></script>-->
		<script>
			var user_id;
			var address;
			var addressnumber;
			var jobtype;
			var community;
			var workertype;
			var workertypenumber;
			var skills;
			var skillsnumber;
			var areavalue;
			var unit;
			var money;
			var operation;
			var updataid;
			var job_id;
			var urgent_status;
			var jobitem_id;
            var old_back = mui.back;
			//mui初始化
			mui.init({
				swipeBack: true //启用右滑关闭功能
			});

			mui.plusReady(function() {
				var self = plus.webview.currentWebview();
				user_id = self.user_id;
				address = self.address;
				addressnumber = self.addressnumber;
				jobtype = self.jobtype;
				community = self.community;
				workertype = self.workertype;
				workertypenumber = self.workertypenumber;
				skills = self.skills;
				skillsnumber = self.skillsnumber;
				areavalue = self.areavalue;
				unit = self.unit;
				money = self.money;
				operation = self.operation;
				updataid = self.updataid;
				job_id = self.job_id;
				jobitem_id=self.jobitem_id;
				urgent_status=self.urgent_status;
				pre_start_date=self.pre_start_date;
			})

			//alert("本地存储转存"+localStorage.getItem("user_id"))
			/*			function getUrlParam (name) {
			     var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
			     var r = window.location.search.substr(1).match(reg);
			     if (r!= null) {
			        return unescape(r[2]);
			     }else{
			        return null;
			     }
			}    
			//获取url中的targetId参数
			var targetId = getUrlParam('targetId');
			console.log(targetId);alert("url传值"+targetId);*/

			//如果是修改页面进入此页面，
			if(operation == 1) {
				document.getElementById("pubbt").innerHTML = "确认修改";
			}
			var urgentsalary = 0;

			//消去自动提示文字，当点击进入时，设置提示文字为空
			function updatetitle(obj) {
				obj.setAttribute("placeholder", "");
			}

			//点击预定金额或者自定义金额的发布时触发，提示确认金额 
			function topublish(obj, num) {

				//点击预定金额

				if(num == 1) {
					var btnArray = ['确认发布', '取消'];
					mui.confirm('加急金额为' + obj.innerText + '，是否发布', '提示', btnArray, function(e) {
						if(e.index == 0) {
							//选择确认发布，跳转到发布函数
							paytype(parseInt(obj.innerText));
						} else {
							//链接到前一页面
						}
					})

					//点击自定义金额的发布
				} else if(num == 2) {
					if(document.getElementById("UrgentSalary").value == "") {
						mui.alert("自定义金额为空，不能紧急发布")
					} else {

						var btnArray = ['确认发布', '取消'];
						mui.confirm('加急金额为' + document.getElementById("UrgentSalary").value + '元，是否发布 ', '提示', btnArray, function(e) {
							if(e.index == 0) {
								paytype(document.getElementById("UrgentSalary").value);
							} else {
								//链接到前一页面
							}
						})
					}
				}

			}
			//发布函数
			function publish(num) {
				console.log(operation+"operation");
				//如果其中存在某条数据为空，可能会导致发布失败时，提示并跳转回之前页面
				if(user_id == null || addressnumber == null || community == null || workertypenumber == null || skillsnumber == null || jobtype == null || areavalue == null || unit == null || money == null || num == null) {
					mui.alert('请在试一次', '数据错误', function(e) {
						errordatajump();
					});
					
				}

				//判断是否为修改操作，设置不同的提交数据
				/*判断是普通发布还是修改还是添加*/
				if(operation == 0) {
					var str = {
						"user_id": user_id,
						"area_code": addressnumber,
						"community_name": community,
						"jobtype_id": workertypenumber,
						"skills_id": skillsnumber,
						"decoration_type": jobtype,
						"area": areavalue,
						"unit": unit,
						"salary": money,
						"urgent_status": "1",
						"urgent_fee": num,
						"pre_start_date":pre_start_date
					};
					var urltz = url_3 + "add_job.do?jsoncallback=?";
				}
				//修改
				if(operation == 1) {
					var str = {
						"id": jobitem_id,
						"job_id": job_id,
						"community_name": community,
						"jobtype_id": workertypenumber,
						"skills_id": skillsnumber,
						"decoration_type": jobtype,
						"area": areavalue,
						"unit": unit,
						"salary": money,
						"urgent_fee": num,
						"urgent_status": "1",
						"pre_start_date":pre_start_date
					};
					var urltz = url_3 + "update_jobitem.do?jsoncallback=?";
				}
				//添加
				if(operation == 2) {
					var str = {
//						"job_id": job_id,
//						"jobtype_id": selectedtype,
//						"skills_id": selectedskills,
//						"area": workload,
//						"unit": workunit,
//						"salary": selectedsalary,
//						"urgent_fee": 0,
//						"urgent_status": 0,
//						"pre_start_date":
						"job_id": job_id,
						"jobtype_id": workertypenumber,
						"skills_id": skillsnumber,
						"decoration_type": jobtype,
						"area": areavalue,
						"unit": unit,
						"salary": money,
						"urgent_fee": num,
						"urgent_status": "1",
						"pre_start_date":pre_start_date
					};
					console.log("job_id"+job_id);
					console.log("workertypenumber"+workertypenumber);
					console.log("skills_id"+skillsnumber);
					console.log("areavalue"+areavalue);
					console.log("unit"+unit);
					console.log("money"+money);
					console.log("num"+num);
					console.log("pre_start_date"+pre_start_date);
					var urltz = url_3 + "add_jobitem.do?jsoncallback=?";
				}
				var w2 = plus.nativeUI.showWaiting("正在发布...\n", {
					
				});
				$.ajax({
					contentType: "application/json",
					type: "GET",
					url: urltz,
					data: str,
					dataType: "json",
					success: function(data) {
						w2.close();
						var timeset = 1;
						var timer = setInterval(function() {
							if(timeset == 0) {
								clearInterval(timer);
								w2.close();
								if(data.flag == 1) {
									mui.toast('发布成功');
									pubsuccjump();
								} else if(data.flag == 0) {
									mui.toast('发布失败');
								} else {
									mui.toast('操作失败');
								}
							} else {
								--timeset;
							}
						}, 200);

					},
					error: function() {
						w2.close();
						mui.alert('网络连接错误', '错误', function() {});
					}
				});
			}

			function pubsuccjump() {
				old_back();
				var list = plus.webview.currentWebview().opener();
								 //触发父页面的自定义事件(refresh),从而进行刷新
								  mui.fire(list, 'topublish');
								  //返回true,继续页面关闭逻辑
								return true;

			}

			function errordatajump() {
				old_back();
				var list=plus.webview.currentWebview().opener();
				mui.fire(list,'topublish');
				return true;
			}

			function paytype(num) {
				var btnArray = ['微信支付', '直接发布'];
				mui.confirm('选择发布方式', '提示', btnArray, function(e) {
					if(e.index == 1) {
						//选择直接发布，跳转到发布函数
						console.log("2");
						publish(num);
					} else {
						console.log("3")
						wechatpay();
					}
				})
			}


function wechatpay(){}
			/*function wechatpay() {
				$('.Save_Patient_Msg').click(function() {
					$('.Save_Patient_Msg').off('click');
					var hrdfId = getOrderId();
					var txnAmt = $('.sum_pay.font-red').html();

					var data = {
						orderId: hrdfId,
						txnAmt: "0.01",
						prodDesc: "远程诊断服务",
						callType: "JSAPI",
						access_token: getUrlParam("access_token")
					};

					$.ajax({
						type: 'POST',
						url: '/hims/api/commonPay/queryTransNo?access_token=' + getUrlParam('access_token'),
						dataType: 'json',
						contentType: 'application/json',
						data: JSON.stringify(data),
						success: function(Wxres) {
							if(!Wxres) {
								$.alert('服务器拥堵，请稍后访问')
							} else {
								console.log(Wxres);
								if(Wxres.data.respCode == 'fail') {
									$.alert(Wxres.data.respMsg);
								} else {
									//10 微信支付接口
									// 10.1 发起一个支付请求
									// 注意：此 Demo 使用 2.7 版本支付接口实现，建议使用此接口时参考微信支付相关最新文档。
									var param = Wxres.data;
									wx.config({
										debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
										appId: 'wx403ead26691402fb', // 必填，公众号的唯一标识
										timestamp: param.timestamp, // 必填，生成签名的时间戳
										nonceStr: param.noncestr, // 必填，生成签名的随机串
										signature: param.signJs, // 必填，调用js签名，
										jsApiList: ['chooseWXPay'] // 必填，需要使用的JS接口列表，这里只写支付的
									});
									wx.chooseWXPay({
										timestamp: param.timestamp, // 支付签名时间戳，注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
										nonceStr: param.noncestr, // 支付签名随机串，不长于 32 位
										package: "prepay_id=" + param.transNo, // 统一支付接口返回的prepay_id参数值，提交格式如：prepay_id=***）
										signType: "MD5", // 签名方式，默认为'SHA1'，使用新版支付需传入'MD5'
										paySign: param.sign, // 支付签名
										success: function(res) {
											if(res.errMsg == "chooseWXPay:ok") {
												//alert("支付成功");
												window.location.href = "/hims/weixin/pages/Order_ok.html?access_token=" + getUrlParam("access_token");
											} else {
												alert(res.errMsg);
											}
										},
										cancel: function(res) {
											//alert('取消支付');
										}
									});
								}

							}
						},
						error: function(data) {
							var msg = data.message || data.status;
							$.alert('服务器错误' + msg);
						}
					});
					return false;

				});

				function getUrlParam(name) {
					var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
					var r = window.location.search.substr(1).match(reg); //匹配目标参数
					if(r != null) return unescape(r[2]);
					return null; //返回参数值
				}

			})

			}
*/
			/*function wechatpay() {

				WeixinJSBridge.invoke(
						'getBrandWCPayRequest', {
							"appId"："wx2421b1c4370ec43b", //公众号名称，由商户传入      
							"timeStamp"：" 1395712654", //时间戳，自1970年以来的秒数      
							"nonceStr"："e61463f8efa94090b1f366cccfbbb444", //随机串      
							"package"："prepay_id=u802345jgfjsdfgsdg888", //统一订单号  
							"signType"："MD5", //微信签名方式：      
							"paySign"："70EA570631E4BB79628FBCA90534C63FF7FADD89" //支付签名  
						},
						function(res) {
							<br>　　　　　　　alert(res.err_msg);  
           if(res.err_msg == "get_brand_wcpay_request：ok" ) {}     // 使用以上方式判断前端返回,微信团队郑重提示：res.err_msg将在用户支付成功后返回    ok，但并不保证它绝对可靠。  
       }  
   );  
 
if (typeof WeixinJSBridge == "undefined"){  
   if( document.addEventListener ){  
       document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);  
   }else if (document.attachEvent){  
       document.attachEvent('WeixinJSBridgeReady', onBridgeReady);  
       document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);  
   }  
}else{  
   onBridgeReady();  
}  
			}*/
		</script>
	</body>

</html>
<!--注意的几点，从存储空间取数据时，要需要数据时在取。否则会导致错误。
	             两个页面都存在时，如果在函数头就读取数据，那么两个页面之间再次跳转。因为页面已经存在
	      将不再对存储空间的数进行读取，会导致数据不对应
-->